package com.juzi.wopu.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;

import com.juzi.wopu.domain.OrderJingCai;
import com.juzi.wopu.query.OrderJingCaiQuery;
import com.juzi.wopu.service.IOrderJingCaiService;

public class OrderJingCaiServiceImpl extends BaseServiceImpl<OrderJingCai> implements IOrderJingCaiService{

	@Override
	public double getTotalCount(OrderJingCaiQuery query) {
		String sql="select sum(iMoney) FROM tOrderJingCai where 1=1 ";
		if (query.getMobile()!=null && !query.getMobile().equals("")) {
			sql=sql+" and sUserNo like '%"+query.getMobile()+"%'";
		}
		
		if(query.getBeginDate()!=null && query.getEndDate()!=null){
			SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			sql=sql+" and dtInsert > '"+dateFormat.format(query.getBeginDate())+
					"' and dtInsert < '"+dateFormat.format(query.getEndDate())+"'";
		}
		
		if (query.getCompanyCode()!=null && query.getCompanyCode()!=-1) {
			sql=sql+" and iCompany = "+query.getCompanyCode();
		}
		
		double totalCount=-1;
		ResultSet resultSet=BaseDao.executeQuerySql(sql);
		if(resultSet!=null){
			try {
				while(resultSet.next()){
					totalCount=resultSet.getDouble(1);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return totalCount;
	}


}
